package com.duan.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.duan.goods.pojo.Classify;
import com.duan.goods.service.ClassifyService;
import com.duan.goods.mapper.ClassifyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
* @author lenovo
* @description 针对表【goods_classify(分类表)】的数据库操作Service实现
* @createDate 2024-07-30 12:30:23
*/
@Service
public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify>
    implements ClassifyService{

    @Autowired
    private ClassifyMapper classifyMapper;

    @Override
    public List<Classify> selectAll() {
        LambdaQueryWrapper<Classify> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Classify::getIsDelete,0);
        return classifyMapper.selectList(queryWrapper);
    }

    @Override
    public List<Classify> selectList(Classify classify) {
//        LambdaQueryWrapper<Classify> queryWrapper
        return null;
    }

    @Override
    public Integer insert(Classify classify) {
        return classifyMapper.insert(classify);
    }

    @Override
    public Integer delete(String ids) {
        try {
            String[] split = ids.split(",");
            for (String id : split) {
                Classify classify = new Classify();
                classify.setId(Long.parseLong(id));
                classify.setIsDelete(1);
                classifyMapper.updateById(classify);
            }
            return 1;
        }catch (Exception e){
            return -1;
        }
    }

    @Override
    public Integer update(Classify classify) {
        return classifyMapper.updateById(classify);
    }
}




